import {
    AfterContentChecked, AfterViewChecked, AfterViewInit, Component, DoCheck, ElementRef, Input, OnChanges, OnInit,
    ViewChild
} from '@angular/core';
import {ServerSocket} from "@core/services/ws.service";

@Component({
  selector: 'app-c-qq',
  templateUrl: './c-qq.component.html',
  styleUrls: ['./c-qq.component.less']
})
export class CQqComponent implements OnInit, AfterViewInit, AfterViewChecked, OnChanges, DoCheck, AfterContentChecked {
    @Input() data;
    @Input() socket;
    @Input() IPPORT;
  @ViewChild('dialogBox') dialogBox: ElementRef;
    @ViewChild('dialogList') dialogList: ElementRef;

    constructor(public ws: ServerSocket) { }

  ngOnInit() {
  }

    _answerList = [];
    // 正式时为父组件socket接收数据 @Input()至此组件;
    @Input()
    set answerList(value) {
        this._answerList = value;
    }

    get answerList() {
        return this._answerList;
    }

    ngDoCheck() {

    }
    ngAfterViewChecked() {
        if (this._answerList.length > 0) {
            this.dialogBox.nativeElement.scrollTop = this.dialogList.nativeElement.offsetHeight - this.dialogBox.nativeElement.offsetHeight;
        }
    }


    // i = 0;
  // 测试
  // time;
  ngAfterViewInit() {
      // if (!this.socket) {
      //     this.time = setInterval(() => {
      //         this.answerList.push({
      //             img: '',
      //             name: '学生',
      //             time: '2018-01-02 20:00:0' + this.i++,
      //             answer: '回答内容'
      //         });
      //         this.dialogBox.nativeElement.scrollTop = this.dialogList.nativeElement.offsetHeight - this.dialogBox.nativeElement.offsetHeight + 200;
      //     }, 5000);
      // }
  }

  ngAfterContentChecked() {
  }

  ngOnChanges() {
  }

}
